<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>

    <link rel="stylesheet" href="../../static/css/bootstrap.min.css">
    <script src="../../static/js/axios-0.18.0.js"></script>
    <script src="../../static/js/vue.js"></script>
    <script src="../../static/plugins/echarts/echarts.js"></script>
    <!--引入样式-->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
<body class="hold-transition">
<div id="app">
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input @keyup.enter.native="findPage()" placeholder="商品名称" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <template>
                    <h4 class="el-icon-help">选择状态</h4>
                    <el-select placeholder="全部商品" v-model="findstatus" @change="findPage()">
                        <el-option key="1" label="全部商品" value=""></el-option>
                        <el-option key="2" label="待审核" value="3"></el-option>
                        <el-option key="3" label="正常" value="1"></el-option>
                        <el-option key="4" label="违规" value="0"></el-option>
                        <el-option key="5" label="已售出" value="4"></el-option>
                        <el-option key="6" label="已删除" value="2"></el-option>
                    </el-select>
                </template>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="commname" label="名称" align="center"></el-table-column>
                <el-table-column prop="category" label="类别" align="center"></el-table-column>
                <el-table-column prop="commdesc" label="描述" align="center">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="light" :content="scope.row.commdesc" placement="top-start" style="width: 400px">
                            <span>{{scope.row.commdesc.substring(0,16)}}...</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column prop="createtime" label="时间" align="center"></el-table-column>
                <el-table-column label="操作"  align="center" width="300px">
                    <template slot-scope="scope">
                        <el-button-group>
                            <el-button v-if="scope.row.commstatus === 1" type="danger" size="mini" @click="weigui(scope.row)">违规</el-button>
                            <el-button v-if="scope.row.commstatus === 3" type="danger" size="mini" @click="weigui(scope.row)">违规</el-button>
                            <el-button v-if="scope.row.commstatus === 4" type="primary" size="mini">已售出</el-button>
                            <el-button v-if="scope.row.commstatus === 3" type="success" size="mini" @click="pass(scope.row)">通过审核</el-button>
                            <el-button v-if="scope.row.commstatus === 2" type="info" size="mini">已删除</el-button>
                            <el-button  type="primary" size="mini" @click="xiangqing(scope.row)">详情</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
        </div>
    </div>

</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            findstatus: '',//0违规，1正常，2删除过的，3待审核，4已售出
            dataList: [],//当前页要展示的分页列表数据
            oneData:{},//行数据
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },

        methods: {
            //分页查询
            findPage() {
                console.log(this.findstatus);
                //发送ajax请求，发送分页请求参数（每页条数，查询条件）
                var page ={
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/commodity/findall?commstatus="+this.findstatus,page).then((res)=>{
                    //处理响应数据
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //页面更改时，再次请求数据
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //设置违规
            weigui(row){
                this.$confirm("确认设置"+row.username+"违规吗?","提示",{type:'warning'}).then(()=>{
                    axios.post("/commodity/violation",row).then((res)=>{
                        if(res.data.flag){
                            //设置违规成功,重新请求页面
                            this.$message.success(res.data.message);
                            this.findPage();
                        }else{
                            this.$message.error(res.data.message);
                        }
                    }).catch(()=>{
                        //请求失败
                        this.$message.error("请求失败");
                    })
                }).catch(()=>{
                    this.quxiao();
                })
            },
            quxiao(){
                this.$message.warning("已取消");
            },
            //审核通过
            pass(row){
                this.$confirm("确认"+row.commname+"通过审核吗？","提示",{type:"warning"}).then(()=>{
                    //axios请求，解封用户
                    axios.post("/commodity/pass",row).then((res)=>{
                        if(res.data.flag){
                            //成功，重新查询页面并其实
                            this.findPage();
                            this.$message.success(res.data.message);
                        }else{
                            //提示失败
                            this.$message.error(res.data.message);
                        }
                    })
                }).catch(()=>{
                    this.quxiao();
                })
            },
            //查看详情
            xiangqing(row){
                window.open("/commodity/detail/"+row.commid,'_blank');
            }
        }
    })
</script>
</html>